home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Canvas;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.util.Random;
-
- public class FireworksCanvas2 extends Canvas implements Runnable {
- Thread appThread;
- Image osImage;
- Graphics osg;
- Color bkColor;
- Image bkImage;
- int rocketCount;
- Random randomizer;
- double[] radius;
- int[] centerX;
- int[] centerY;
- double[] currRadius;
- int newX;
- int newY;
- Color[] colors;
- int[] colorIndex;
- double[] cosines;
- double[] sines;
-
- public FireworksCanvas2(Applet var1, int var2) {
- this.GetParameters(var1, var2);
- this.randomizer = new Random(System.currentTimeMillis());
- this.colors = new Color[13];
- this.colors[0] = Color.black;
- this.colors[1] = Color.blue;
- this.colors[2] = Color.cyan;
- this.colors[3] = Color.darkGray;
- this.colors[4] = Color.gray;
- this.colors[5] = Color.green;
- this.colors[6] = Color.lightGray;
- this.colors[7] = Color.magenta;
- this.colors[8] = Color.orange;
- this.colors[9] = Color.pink;
- this.colors[10] = Color.red;
- this.colors[11] = Color.white;
- this.colors[12] = Color.yellow;
- }
-
- void GetParameters(Applet var1, int var2) {
- String var3 = var1.getParameter("fireworksBkColor" + var2);
- this.bkColor = AppletParam2.GetColor(var3, (Color)null);
- if (this.bkColor != null) {
- ((Component)this).setBackground(this.bkColor);
- }
-
- var3 = var1.getParameter("fireworksBkImage" + var2);
- this.bkImage = var1.getImage(var1.getCodeBase(), var3);
- }
-
- public void Start() {
- this.appThread = new Thread(this);
- this.appThread.start();
- }
-
- public void Stop() {
- this.appThread.stop();
- this.appThread = null;
- }
-
- public void update(Graphics var1) {
- if (this.osImage == null) {
- this.osImage = ((Component)this).createImage(((Component)this).size().width, ((Component)this).size().height);
- this.osg = this.osImage.getGraphics();
- }
-
- this.osg.setColor(((Component)this).getBackground());
- this.osg.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
- if (this.bkImage != null) {
- int var2 = this.bkImage.getWidth(this);
- int var3 = this.bkImage.getHeight(this);
- int var4 = ((Component)this).size().width / var2;
- int var5 = ((Component)this).size().height / var3;
- ++var4;
- ++var5;
-
- for(int var6 = 0; var6 < var5; ++var6) {
- for(int var7 = 0; var7 < var4; ++var7) {
- this.osg.drawImage(this.bkImage, var7 * var2, var6 * var3, this);
- }
- }
- }
-
- for(int var8 = 0; var8 < this.rocketCount; ++var8) {
- this.osg.setColor(this.colors[this.colorIndex[var8]]);
-
- for(int var9 = 0; var9 < 16; ++var9) {
- for(double var11 = this.currRadius[var8]; var11 > this.currRadius[var8] - (double)10.0F; var11 -= (double)2.0F) {
- if (var11 > (double)0.0F) {
- this.newX = this.centerX[var8] + (int)(this.cosines[var9] * var11);
- this.newY = this.centerY[var8] + (int)(this.sines[var9] * var11);
- this.osg.drawLine(this.newX, this.newY, this.newX, this.newY);
- }
- }
- }
- }
-
- var1.drawImage(this.osImage, 0, 0, this);
- }
-
- public void run() {
- while(true) {
- try {
- ((Component)this).repaint();
- this.UpdateRockets();
- Thread.sleep(100L);
- } catch (InterruptedException var1) {
- }
- }
- }
-
- public Dimension minimumSize() {
- return new Dimension(10, 10);
- }
-
- public Dimension preferredSize() {
- return new Dimension(10, 10);
- }
-
- public synchronized void reshape(int var1, int var2, int var3, int var4) {
- super.reshape(var1, var2, var3, var4);
- this.osImage = null;
- this.osg = null;
- this.Initialize();
- }
-
- public boolean imageUpdate(Image var1, int var2, int var3, int var4, int var5, int var6) {
- ((Component)this).repaint();
- return true;
- }
-
- void Initialize() {
- this.rocketCount = Math.max(Math.abs(this.randomizer.nextInt()) % 10, 3);
- this.radius = new double[this.rocketCount];
- this.centerX = new int[this.rocketCount];
- this.centerY = new int[this.rocketCount];
- this.currRadius = new double[this.rocketCount];
- this.colorIndex = new int[this.rocketCount];
-
- for(int var1 = 0; var1 < this.rocketCount; ++var1) {
- this.centerX[var1] = Math.abs(this.randomizer.nextInt()) % (((Component)this).size().width - 20);
- this.centerY[var1] = Math.abs(this.randomizer.nextInt()) % (((Component)this).size().height - 20);
- this.radius[var1] = (double)Math.max(30, Math.abs(this.randomizer.nextInt()) % 200);
- this.currRadius[var1] = (double)0.0F;
- this.colorIndex[var1] = Math.abs(this.randomizer.nextInt()) % 12;
- }
-
- int var2 = 0;
- this.cosines = new double[16];
- this.sines = new double[16];
-
- for(double var3 = (double)0.0F; var3 < (Math.PI * 2D); var3 += (Math.PI / 8D)) {
- this.cosines[var2] = Math.cos(var3);
- this.sines[var2] = Math.sin(var3);
- ++var2;
- }
-
- }
-
- void UpdateRockets() {
- for(int var1 = 0; var1 < this.rocketCount; ++var1) {
- int var10002 = this.currRadius[var1]++;
- if (this.currRadius[var1] >= this.radius[var1]) {
- this.centerX[var1] = Math.abs(this.randomizer.nextInt()) % (((Component)this).size().width - 20);
- this.centerY[var1] = Math.abs(this.randomizer.nextInt()) % (((Component)this).size().height - 20);
- this.radius[var1] = (double)Math.max(30, Math.abs(this.randomizer.nextInt()) % 100);
- this.currRadius[var1] = (double)0.0F;
- this.colorIndex[var1] = Math.abs(this.randomizer.nextInt()) % 12;
- }
- }
-
- }
- }
-